package jp.dodododo.reloadable.filter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class FilterWrapperContainer {
	private static final List<FilterWrapper> SERVLET_WRAPPER_LIST = new ArrayList<FilterWrapper>();

	public static void register(FilterWrapper filterWrapper) {
		SERVLET_WRAPPER_LIST.add(filterWrapper);
	}

	public static void remove(FilterWrapper filterWrapper) {
		SERVLET_WRAPPER_LIST.remove(filterWrapper);
	}

	public static void initAll() {
		for (Iterator<FilterWrapper> iter = SERVLET_WRAPPER_LIST.iterator(); iter.hasNext();) {
			FilterWrapper filterWrapper = iter.next();
			try {
				filterWrapper.initTarget();
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	}

	public static void destroyAll() {
		for (Iterator<FilterWrapper> iter = SERVLET_WRAPPER_LIST.iterator(); iter.hasNext();) {
			FilterWrapper filterWrapper = iter.next();
			try {
				filterWrapper.destroyTarget();
			} catch (Throwable ignore) {
				ignore.printStackTrace();
			}
		}
	}

}
